// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null
  },
  postX: function (url, data,callback) {
    wx.request({
      url: http + url,
      data: data,
      method: 'post',
      header: {
        'Content-type': 'application/x-www-form-urlencoded',
        // application/x-www-form-urlencoded ： <form encType=””>中默认的encType，form表单数据被编码为key/value格式发送到服务器（表单默认的提交数据的格式）
        'Authorization':'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImJjMjg2YzIxLTQzZjEtNGJlNS05NmE5LWUzMTA4MmFkODg0ZCJ9.HWakJcl0D-QiD-ii0EorozvItjKEgVvLA9qZMADfU1e7cTSuF9My2bFxoJxHXmz5OUKo5zrK4Tma2LvC-mxcsQ'
      },
      success: function(res) {
        return typeof callback == "function" && callback(res.data)
      },
      fail: function(res) {
        return typeof callback == "function" && callback(false)
      }
    })
  },
  
  getX: function (url, data, callback) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: http + url,
        data: data,
        method: 'get',
        header: {
          'Content-Type': 'application/json',
          'Authorization':'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImJjMjg2YzIxLTQzZjEtNGJlNS05NmE5LWUzMTA4MmFkODg0ZCJ9.HWakJcl0D-QiD-ii0EorozvItjKEgVvLA9qZMADfU1e7cTSuF9My2bFxoJxHXmz5OUKo5zrK4Tma2LvC-mxcsQ'
        },
        success: function (res) {
          resolve(typeof callback == "function" && callback(res.data))
        },
        fail: function (res) {
          reject(typeof callback == "function" && callback(false))
        }
      })
    })
  }
})
